local hengzuishenmian = fk.CreateSkill {
  name = "hengzuishenmian",
  tags = { Skill.Compulsory },
}

Fk:loadTranslationTable{
  ["hengzuishenmian"] = "衡罪",
  [":hengzuishenmian"] = "锁定技，每名角色每回合限一次，当其他角色造成伤害后，你视为对受伤的目标使用一张杀。",

  ["#hengzuishenmian"] = "你可以视为对目标使用一张杀。"
}

hengzuishenmian:addEffect(fk.Damaged, {
  can_trigger = function(self, event, target, player, data)
    local sha = data.from
    return player:hasSkill(self.name) 
    and not target.dead
    and  player:getMark("#@hengzuishenmian_" .. sha.id) == 0
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askToSkillInvoke(player, self.name, "#hengzuishenmian", true)
  end,
  on_use = function(self, event, target, player, data)
    local sha = data.from
    local room = player.room
    if not target.dead then
        room:addPlayerMark(player, "#@hengzuishenmian_" .. sha.id, 1)
        if player:getMark("@caijvewanxv",player) > 0 and not target:isNude() then
            local id = room:askToChooseCard(player, {
            target = target,
            flag = "he",
            skill_name = self.name,
             })
            room:throwCard(id, self.name, target, player)
        end
        room:useVirtualCard("slash", nil, player, target, self.name, true)
    end
  end,
})

hengzuishenmian:addEffect(fk.TurnStart, {
  anim_type = "support",
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self.name)
  end,
  on_cost = function(self, event, target, player, data)
    return true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    for _, p in ipairs(room:getAlivePlayers()) do
      room:setPlayerMark(player, "#@hengzuishenmian_" .. p.id, 0)
    end
  end,
})

return hengzuishenmian